<html>
<head>
<?php

$status = $accountid = $accountinf =  null; //declare vars

$conn = mysql_connect('cash2uca.ipagemysql.com', 'cash2uca', 'actW3740!@#$'); 
	if (!$conn) { 
	    die('Could not connect: ' . mysql_error()); 
		} 

mysql_select_db(cash2uca);

if(isset($_POST["status"]) && is_numeric($_POST["status"]))
{
    $status = $_POST["status"];
}

if(isset($_POST["accountid"]) && is_numeric($_POST["accountid"]))
{
    $accountid = $_POST["accountid"];
}

if(isset($_POST["accountinf"]) && is_numeric($_POST["accountinf"]))
{
    $accountinf = $_POST["accountinf"];
}

?>

<script language="JavaScript">

function autoSubmit()
{
    var formObject = document.forms['newprocess'];
    formObject.submit();
}

</script>
</head>
<body>
<form name="newprocess" method="post">

    <!-- status SELECTION -->
    
    <select style="width: 220px;" name="status" onChange="autoSubmit();">
	<option value="null">Please select application status</option>
	<option value="1" <?php if($status == 1) echo " selected"; ?>>New Application</option>
	<option value="2" <?php if($status == 2) echo " selected"; ?>>Loan Paid</option>
        <option value="3" <?php if($status == 3) echo " selected"; ?>>Scheduled Repaying</option>
       	<option value="4" <?php if($status == 4) echo " selected"; ?>>NSF</option>
       	<option value="5" <?php if($status == 5) echo " selected"; ?>>Failed Application</option>

    </select>

    <br><br>

    <!-- accountid SELECTION BASED ON status VALUE -->
        
    <?php
    
    if($status != null && is_numeric($status))
    {
    
    ?>
    
    <select style="width: 200px;" name="accountid" onChange="autoSubmit();">        
        <option value="null">Please select one AccountID</option>
        
        <?php
        
        //POPULATE DROP DOWN MENU WITH COUNTRIES FROM A GIVEN status


        $sql = "SELECT * FROM Applications WHERE NewApp=$status ORDER BY AccountID";
        $accounts = mysql_query($sql,$conn);
        
        while($row = mysql_fetch_array($accounts))
        {        
            echo ("<option value=\"$row[AccountID]\" " . ($accountid == $row["AccountID"] ? " selected" : "") . ">$row[AccountID]</option>");        
        }
        
        ?>
        
    </select>
    
    <?php
    
    }
    
    ?>
    
    <br><br>
    
    <?php
    
    if($accountid != null && is_numeric($accountid) && $status != null)
    {
    
    ?>
    
    <table name="accountinf" onChange="autoSubmit();">
		<tr><td width="700" align="center">Please Decide to Apporve or Refuse</td></tr>

        <?php
        
        //POPULATE DROP DOWN MENU WITH STATES FROM A GIVEN status, COUNTRY
        
        $sql = "SELECT * FROM Applications WHERE AccountID = $accountid ";
        $states = mysql_query($sql,$conn);
        
        while($row = mysql_fetch_array($states))
        {
              echo "<tr>";
		  echo "<td>" . $row['AccountID'] . "</td>";
		  echo "<td>" . $row['BAmount'] . "</td>";
		  echo "<td>" . $row['Costs'] . "</td>";
		  echo "<td>" . $row['FirstPayDay'] . "</td>";
		  echo "<td>" . $row['NumberofVisits'] . "</td>";
		  echo "</tr>"; 
        }
        
        ?>    
        
    </table>
    
    <?php
    
    }
    
    ?>
    
    

</form>
</body>
</html>


